﻿// HSS.Data.ModelGenerator.MainForm.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       MainForm.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/24/2010
// ----------------------------------------------------------------------------
namespace HSS.Data.ModelGenerator
{
	#region Using Directives
	using System;
	using System.Collections.Generic;
	using System.IO;
	using System.Windows.Forms;
	using HSS.Data.ModelGenerator;
	using HSS.Forms;
	using ICSharpCode.TextEditor;
	using ICSharpCode.TextEditor.Document;
	using HSS.Data;
	using System.Text;
	#endregion

	#region MainForm
	/// <summary>
	/// The applications main form.
	/// </summary>
	public partial class MainForm : Form
	{
		#region Constants
		const string nameSpace = "DefaultNameSpace";
		const string baseClass = "Entity";
		const int classFile = 0;
		const int sqlFile = 1;
		#endregion

		#region Fields
		Dictionary<string, BatchItem> batch = new Dictionary<string, BatchItem>();
		Dictionary<string, Processor> processors;
		ObjectDefinition currentObject;
		TextEditorControl activeEditor;
		bool initialized;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		public MainForm()
		{
			this.InitializeComponent();
		}
		internal bool Initialize(out Exception initError)
		{
			initError = null;
			this.initialized = false;

			try
			{
				this.Cursor = Cursors.WaitCursor;

				this.tsbRemoveItem.Enabled = false;

				var isProtectedSet = AppUserData.Get<bool>("chkProtectedSet", true);
				this.chkProtectedSet.Checked = isProtectedSet;
				this.chkProtectedSet.CheckedChanged += new System.EventHandler(this.chkProtectedSet_CheckedChanged);

				this.cboTemplate.DataSource = AppUserConfiguration<TemplateData>.Items;
				this.cboEntityTemplate.DataSource = AppUserConfiguration<TemplateData>.Items;

				if (this.Connect())
					this.RefreshLists();

				this.txtNameSpace.Text = AppUserData.GetString(nameSpace);
				if (string.IsNullOrEmpty(this.txtNameSpace.Text))
					this.txtNameSpace.Text = "HSS.Data";

				this.txtBaseClassName.Text = AppUserData.GetString(baseClass);
				if (string.IsNullOrEmpty(this.txtBaseClassName.Text))
					this.txtBaseClassName.Text = "Entity";

				var dir = Path.GetDirectoryName(this.GetType().Assembly.Location);
				var fsmProvider = new FileSyntaxModeProvider(dir);
				HighlightingManager.Manager.AddSyntaxModeFileProvider(fsmProvider); // Attach to the text editor.

				this.txtDOMCode.SetHighlighting("C#");
				this.txtDOMCode.ActiveTextAreaControl.TextArea.MouseClick += new MouseEventHandler(DOMCode_MouseClick);

				this.txtDOMEntity.SetHighlighting("C#");
				this.txtDOMEntity.ActiveTextAreaControl.TextArea.MouseClick += new MouseEventHandler(DOMEntity_MouseClick);

				this.txtSqlCode.SetHighlighting("SQL");

				this.btnApplyOptionChanges.Enabled = false;

				this.FormClosing += delegate
					{
						AppUserData.Set<bool>("chkProtectedSet", this.chkProtectedSet.Checked);
					};

				this.initialized = true;
				return true;

			}
			catch (Exception ex)
			{
				initError = ex;
			}
			finally
			{
				this.Cursor = Cursors.Default;
			}

			return false;
		}

		#endregion

		#region Methods

		bool Connect()
		{
			using (var manager = new ConnectionStringProfiles())
			{
				if (manager.ShowDialog(Program.MainForm) == DialogResult.OK)
				{
					DataAccessContext.DefaultConnection = manager.SelectedConnection;
					bool success = null != DataAccessContext.DefaultConnection;
					this.tsbRefresh.Enabled = success;
					this.tsmRefresh.Enabled = success;
					return success;
				}
				return false;
			}
		}

		void RefreshLists()
		{
			try
			{
				this.dbExplorer1.DatabaseChanged -= new EventHandler<EventArgs>(dbExplorer1_DatabaseChanged);
				this.dbExplorer1.NodeSelected -= new EventHandler<DatabaseObjectSelectedEventArgs>(dbExplorer1_NodeSelected);
				if (null != this.processors)
				{
					this.processors.Clear();
					this.processors = null;
				}
				this.processors = new Dictionary<string, Processor>();

				if (null != DataAccessContext.DefaultConnection)
				{
					this.Cursor = Cursors.WaitCursor;
					this.dbExplorer1.Bind();
					this.dbExplorer1.DatabaseChanged += new EventHandler<EventArgs>(dbExplorer1_DatabaseChanged);
					this.dbExplorer1.NodeSelected += new EventHandler<DatabaseObjectSelectedEventArgs>(dbExplorer1_NodeSelected);
					this.tsbRefresh.Enabled = true;
					this.tsmRefresh.Enabled = true;
				}
				else
				{
					this.tsbRefresh.Enabled = false;
					this.tsmRefresh.Enabled = false;
				}
			}
			catch
			{
				this.tsbRefresh.Enabled = false;
				this.tsmRefresh.Enabled = false;
			}

			this.Cursor = Cursors.Default;
		}

		void RefreshObject()
		{
			if (!initialized)
				return;

			try
			{
				this.Cursor = Cursors.WaitCursor;
				this.btnApplyOptionChanges.Enabled = false;

				#region Validate template(s)
				TemplateData template = this.cboTemplate.SelectedItem as TemplateData;
				if (null == template)
				{
					MsgBox.Show("Unknown or missing Template.");
					return;
				}

				TemplateData entityTemplate = this.cboEntityTemplate.SelectedItem as TemplateData;
				if (null == entityTemplate)
				{
					MsgBox.Show("Unknown or missing Entity Template.");
					return;
				}
				#endregion

				if (null != currentObject)
				{
					#region Process

					Processor processor = null;

					#region Get Object Processor
					if (processors.ContainsKey(this.currentObject.ObjectName))
						processor = processors[this.currentObject.ObjectName];
					// HSS.Data.TableOrViewProcessor, HSS.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=4660a9a904fbb170
					// HSS.Data.StoredProcedureProcessor, HSS.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=4660a9a904fbb170
					if (null == processor)
					{
						processor = new Processor(this.currentObject);
						processors.Add(this.currentObject.ObjectName, processor);
					}
					#endregion

					string output = string.Empty;
					string outputEntity = string.Empty;

					#region Process the Object

					// Update user changes
					processor.CurrentTemplate = template.Contents;
					processor.UsePartialClass = this.chkPartialClass.Checked;
					processor.CurrentEntityTemplate = entityTemplate.Contents;
					processor.NamespaceName = this.txtNameSpace.Text;
					processor.BaseClass = this.txtBaseClassName.Text;
					processor.Creator = Environment.UserName;
					processor.UseDataMemberAttribute = this.chkIncludeDataMember.Checked;
					processor.ImplementPropertyAccessors = this.chkImplementAccessors.Checked;
					processor.CallOnPropertyChanging = this.chkCallOnPropertyChanging.Checked;
					processor.CallValidateProperty = this.chkCallValidateProperty.Checked;
					processor.CallOnPropertyChanged = this.chkCallOnPropertyChanged.Checked;
					processor.ImplementCheckNewValue = this.chkIfNewValue.Checked;
					processor.UsePrivateAccessorForLoad = this.chkLoadUsesAccessor.Checked;
					processor.SetterProtectedIfReadOnly = this.chkProtectedSet.Checked;
					processor.ApplyHSSDBAttributes = this.chkHSSDBAttributes.Checked;

					// Generate code
					processor.Process();

					// Process results
					output = processor.ClassEntityCode;
					outputEntity = processor.ClassContextCode;
					if (null != processor.LastError)
					{
						output = processor.LastError.ToString();
						outputEntity = string.Empty;
						this.DisableOutputToolarbar();
					}
					else
					{
						this.EnableOutputToolarbar();
					}
					#endregion

					#endregion

					#region Update Viewables

					this.lbgOutputHeader.Text = "[" + DataAccessContext.DefaultConnection.DataSource + "].[" + DataAccessContext.DefaultConnection.InitialCatalog + "].[" + currentObject.ObjectName + "]";
					if (currentObject.IsTable)
						this.lbgOutputHeader.Text += " - Table ";
					else
						this.lbgOutputHeader.Text += " - Stored Procedure";

					this.txtDOMCode.Text = output;
					this.txtDOMCode.Refresh();

					if (this.chkPartialClass.Checked)
					{
						this.txtDOMEntity.Text = outputEntity;
						this.txtDOMEntity.Refresh();
					}

					this.txtSqlCode.Text = currentObject.SqlDefinition;
					this.txtSqlCode.Refresh();

					this.dgvSchema.DataSource = processor.SchemaTable;

					#endregion
				}
				else
				{
					#region Update Viewables
					this.lbgOutputHeader.Text = "No object selected";
					this.txtDOMCode.Text = "";
					this.txtDOMCode.Refresh();
					this.txtSqlCode.Text = "";
					this.txtSqlCode.Refresh();
					this.dgvSchema.DataSource = null;
					#endregion
				}

			}
			finally
			{
				// Default to the DOMCode
				this.activeEditor = this.txtDOMCode;
				this.Cursor = Cursors.Default;
			}

		}

		void GenerateBatch()
		{
			if (this.trvBatch.Nodes.Count > 0)
			{
				bool errorsEncountered = false;
				string folder = this.txtOutputFolder.Text;
				var filesSkipped = new List<string>();
				foreach (TreeNode batchNode in this.trvBatch.Nodes)
				{
					try
					{
						var item = batchNode.Tag as BatchItem;

						string path = Path.Combine(folder, item.DataModelFileName);
						if (File.Exists(path) && !chlBatchOverwrite.Checked)
							filesSkipped.Add(item.DataModelFileName);
						else
							File.WriteAllText(path, item.DataModelText);

						if (item.IncludesEntity)
						{
							path = Path.Combine(folder, item.EntityModelFileName);
							if (File.Exists(path) && !chlBatchOverwrite.Checked)
								filesSkipped.Add(item.EntityModelFileName);
							else
								File.WriteAllText(path, item.EntityModelText);
						}
					}
					catch { errorsEncountered = true; }
				}

				if (errorsEncountered)
					MessageBox.Show(this, "Some file could not be generated successfully. Ensure the files do not already exist and are not readonly and you have permissions to write to the folder selected.", "Batch Generation", MessageBoxButtons.OK, MessageBoxIcon.Warning);

				if (filesSkipped.Count > 0)
				{
					var str = new StringBuilder();
					str.AppendLine("The following files already exist in folder [ " + folder + " ] and were not written to disk:");
					str.AppendLine();
					foreach (var fileName in filesSkipped)
						str.AppendFormat("	{0}{1}", fileName, Environment.NewLine);
					str.AppendLine();
					MessageBox.Show(this, str.ToString(), "Batch Generation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
					str = null;
				}
			}
		}


		void EnableOutputToolarbar()
		{
			this.tsbAddToBatch.Enabled = true;
			this.tsbRefreshOutput.Enabled = true;
		}
		void DisableOutputToolarbar()
		{
			this.tsbAddToBatch.Enabled = false;
			this.tsbRefreshOutput.Enabled = false;
		}

		#endregion

		#region Event Handlers

		void dbExplorer1_NodeSelected(object sender, DatabaseObjectSelectedEventArgs e)
		{
			this.currentObject = e.SelectedObject;

			if (null != this.currentObject)
			{
				this.txtClassName.Text = this.currentObject.ClassName;
				if (batch.ContainsKey(this.currentObject.ObjectName))
					this.tsbAddToBatch.Text = "Update batch";
				else
					this.tsbAddToBatch.Text = "Add to batch";
			}
			else
			{
				this.txtClassName.Text = string.Empty;
				this.tsbAddToBatch.Text = "Add to batch";
			}

			this.RefreshObject();
		}
		void dbExplorer1_DatabaseChanged(object sender, EventArgs e)
		{
			if (null != this.processors)
			{
				this.processors.Clear();
				this.processors = null;
			}
			this.processors = new Dictionary<string, Processor>();
		}

		#region Main Menu/Toolbar
		void tsmConnect_Click(object sender, EventArgs e)
		{
			if (Connect())
				this.RefreshLists();
		}
		void tsmRefresh_Click(object sender, EventArgs e)
		{
			this.RefreshLists();
		}
		void tsmTemplates_Click(object sender, EventArgs e)
		{
			using (TemplateManager editor = new TemplateManager())
			{
				if (editor.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
				{
					int currentIndex = this.cboTemplate.SelectedIndex;
					this.cboTemplate.DataSource = AppUserConfiguration<TemplateData>.Items;
					if (this.cboTemplate.Items.Count > 0)
					{
						if (currentIndex > -1)
							this.cboTemplate.SelectedIndex = currentIndex;
					}

					currentIndex = this.cboEntityTemplate.SelectedIndex;
					this.cboEntityTemplate.DataSource = AppUserConfiguration<TemplateData>.Items;
					if (this.cboEntityTemplate.Items.Count > 0)
					{
						if (currentIndex > -1)
							this.cboEntityTemplate.SelectedIndex = currentIndex;
					}

					btnApplyOptionChanges.Enabled = false;
					this.RefreshObject();
				}
			}
		}
		void tsmViewTokens_Click(object sender, EventArgs e)
		{
			using (Tokens token = new Tokens())
				token.ShowDialog(this);
		}
		void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
			using (About about = new About())
				about.ShowDialog(this);
		}
		void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Application.Exit();
		}
		#endregion

		#region Model Toolbar
		void tsbOptions_Click(object sender, EventArgs e)
		{
			if (this.tsbOptions.Checked)
			{
				this.tsbOptions.Text = "Hide Options";
				this.pnlOutputCmds.Visible = true;
			}
			else
			{
				this.tsbOptions.Text = "Show Options";
				this.pnlOutputCmds.Visible = false;
			}
		}
		void tsbAddToBatch_Click(object sender, EventArgs e)
		{
			if (btnApplyOptionChanges.Enabled)
			{
				this.RefreshObject();
			}
			if (null != this.currentObject)
			{
				if (batch.ContainsKey(this.currentObject.ObjectName))
				{
					batch.Remove(this.currentObject.ObjectName);
					this.trvBatch.Nodes.RemoveByKey(this.currentObject.ObjectName);
				}

				var item = new BatchItem()
				{
					DataModelText = this.txtDOMCode.Text,
					DataModelFileName = this.currentObject.ClassName + ".cs",
					IncludesEntity = this.chkPartialClass.Checked,
					EntityModelText = this.txtDOMEntity.Text,
					EntityModelFileName = this.currentObject.ClassName + ".Context.cs",
					Definition = this.currentObject
				};
				batch.Add(this.currentObject.ObjectName, item);
				TreeNode node = this.trvBatch.Nodes.Add(this.currentObject.ObjectName, item.DataModelFileName);
				node.SelectedImageIndex = 4;
				node.ImageIndex = 4;
				node.Tag = item;
				if (this.chkPartialClass.Checked)
				{
					node = node.Nodes.Add(item.EntityModelFileName);
					node.SelectedImageIndex = 8;
					node.ImageIndex = 8;
				}

				this.tsbAddToBatch.Text = "Update batch";

				this.tsbGenerateBatch.Enabled = (this.txtOutputFolder.Text.Length > 0) && (this.trvBatch.Nodes.Count > 0);
			}
		}
		void tsbRefreshOutput_Click(object sender, EventArgs e)
		{
			this.RefreshObject();
		}
		#endregion

		#region Batch Toolbar
		void trvBatch_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (null == this.trvBatch.SelectedNode.Tag)
				this.tsbRemoveItem.Enabled = false;
			else
				this.tsbRemoveItem.Enabled = true;
		}
		void tsbRemoveItem_Click(object sender, EventArgs e)
		{
			if (null == this.trvBatch.SelectedNode)
				return;

			if (null == this.trvBatch.SelectedNode.Tag)
				return;

			var item = this.trvBatch.SelectedNode.Tag as BatchItem;

			if (batch.ContainsKey(item.Definition.ObjectName))
			{
				batch.Remove(this.currentObject.ObjectName);
				this.trvBatch.Nodes.RemoveByKey(item.Definition.ObjectName);
			}

			item = null;
		}
		void tsbGenerateBatch_Click(object sender, EventArgs e)
		{
			this.GenerateBatch();
		}
		private void btnBrowse_Click(object sender, EventArgs e)
		{
			this.tsbGenerateBatch.Enabled = false;
			using (var dlg = new FolderBrowserDialog())
			{
				dlg.Description = "Select the folder where to write the generated files.";
				dlg.ShowNewFolderButton = true;
				dlg.SelectedPath = this.txtOutputFolder.Text;
				try
				{
					if (dlg.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
						return;
					this.txtOutputFolder.Text = dlg.SelectedPath;
				}
				finally
				{
					this.tsbGenerateBatch.Enabled = (this.txtOutputFolder.Text.Length > 0) && (this.trvBatch.Nodes.Count > 0);
				}
			}
		}
		#endregion


		void txtNameSpace_TextChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			AppUserData.Set<string>(nameSpace, this.txtNameSpace.Text);
			btnApplyOptionChanges.Enabled = true;
		}
		private void txtBaseClassName_TextChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			AppUserData.Set<string>(baseClass, this.txtBaseClassName.Text);
			btnApplyOptionChanges.Enabled = true;
		}
		void txtClassName_TextChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			if (null != this.currentObject)
				this.currentObject.ClassName = this.txtClassName.Text;
			btnApplyOptionChanges.Enabled = true;
		}

		void cboTemplate_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}
		void cboEntityTemplate_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}
		void chkProtectedSet_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}
		void tbcOutput_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch (this.tbcOutput.SelectedIndex)
			{
				case classFile:
					switch (this.tbcDOM.SelectedIndex)
					{
						case 0:
							this.activeEditor = this.txtDOMCode;
							break;

						case 1:
							this.activeEditor = this.txtDOMEntity;
							break;

						default:
							break;
					}
					break;

				case sqlFile:
					this.activeEditor = this.txtSqlCode;
					break;

				default:
					this.activeEditor = null;
					break;
			}
		}
		void tbcDOM_SelectedIndexChanged(object sender, EventArgs e)
		{
			switch (this.tbcDOM.SelectedIndex)
			{
				case 0:
					this.activeEditor = this.txtDOMCode;
					break;

				case 1:
					this.activeEditor = this.txtDOMEntity;
					break;
			}
		}

		void chkPartialClass_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			this.cboEntityTemplate.Enabled = chkPartialClass.Checked;
			if (chkPartialClass.Checked)
				this.txtDOMEntity.Enabled = true;
			else
			{
				this.txtDOMEntity.ResetText();
				this.txtDOMEntity.Refresh();
				this.txtDOMEntity.Enabled = false;
			}
			btnApplyOptionChanges.Enabled = true;
		}
		void chkIncludeDataMember_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}
		void chkHSSDBAttributes_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}
		void chkImplementAccessors_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;

			this.chkIfNewValue.Enabled = this.chkImplementAccessors.Checked;
			this.chkIfNewValue.Checked =
				(this.chkImplementAccessors.Checked ? this.chkIfNewValue.Checked : false);

			this.chkCallOnPropertyChanging.Enabled = this.chkImplementAccessors.Checked;
			this.chkCallOnPropertyChanging.Checked =
				(this.chkImplementAccessors.Checked ? this.chkCallOnPropertyChanging.Checked : false);

			this.chkCallValidateProperty.Enabled = this.chkImplementAccessors.Checked;
			this.chkCallValidateProperty.Checked =
				(this.chkImplementAccessors.Checked ? this.chkCallValidateProperty.Checked : false);

			this.chkCallOnPropertyChanged.Enabled = this.chkImplementAccessors.Checked;
			this.chkCallOnPropertyChanged.Checked =
				(this.chkImplementAccessors.Checked ? this.chkCallOnPropertyChanged.Checked : false);

			this.chkLoadUsesAccessor.Enabled = this.chkImplementAccessors.Checked;
			this.chkLoadUsesAccessor.Checked =
				(this.chkImplementAccessors.Checked ? this.chkLoadUsesAccessor.Checked : false);
		}
		void chkCallOnPropertyChanged_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			this.btnApplyOptionChanges.Enabled = true;
		}
		void chkCallValidateProperty_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			this.btnApplyOptionChanges.Enabled = true;
		}
		void chkCallOnPropertyChanging_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			this.btnApplyOptionChanges.Enabled = true;
		}
		void chkIfNewValue_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			this.btnApplyOptionChanges.Enabled = true;
		}
		void chkLoadUsesAccessor_CheckedChanged(object sender, EventArgs e)
		{
			this.DisableOutputToolarbar();
			btnApplyOptionChanges.Enabled = true;
		}

		void DOMCode_MouseClick(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				this.tsmiAddToBatch.Enabled = this.tsbAddToBatch.Enabled;
				this.tsmiAddToBatch.Text = this.tsbAddToBatch.Text;
				this.tsmiRegenerate.Enabled = this.tsbRefreshOutput.Enabled;
				this.DOMCodeContextMenu.Show(this.txtDOMCode, e.Location, ToolStripDropDownDirection.Default);
			}
		}
		void DOMEntity_MouseClick(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				this.tsmiEntityAddToBatch.Enabled = this.tsbAddToBatch.Enabled;
				this.tsmiEntityAddToBatch.Text = this.tsbAddToBatch.Text;
				this.tsmiEntityRegenerate.Enabled = this.tsbRefreshOutput.Enabled;
				this.EntityCodeContextMenu.Show(this.txtDOMEntity, e.Location, ToolStripDropDownDirection.Default);
			}
		}

		void btnApplyOptionChanges_Click(object sender, EventArgs e)
		{
			btnApplyOptionChanges.Enabled = false;
			this.RefreshObject();
		}

		#endregion

		#region CodeDOM ContextMenu
		void tsmiCopy_Click(object sender, EventArgs e)
		{
			if (null != this.currentObject)
				Clipboard.SetText(this.txtDOMCode.ActiveTextAreaControl.SelectionManager.SelectedText);
		}
		void tsmiAddToBatch_Click(object sender, EventArgs e)
		{
			this.tsbAddToBatch_Click(sender, e);
		}
		void tsmiRegenerate_Click(object sender, EventArgs e)
		{
			this.RefreshObject();
		}
		#endregion

		#region EntityDOM Context Menu
		void tsmiEntityCopy_Click(object sender, EventArgs e)
		{
			if (null != this.currentObject)
				Clipboard.SetText(this.txtDOMEntity.ActiveTextAreaControl.SelectionManager.SelectedText);
		}
		void tsmiEntityAddToBatch_Click(object sender, EventArgs e)
		{
			this.tsbAddToBatch_Click(sender, e);
		}
		void tsmiEntityRegenerate_Click(object sender, EventArgs e)
		{
			this.RefreshObject();
		}
		#endregion
	}
	#endregion
}